 
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
#define MAX 200200

int n, m;
vector<pair<pair<int, int>, int>> A;
set<int> S;
int f[MAX];

int getf(int x) {
    return (x == f[x]) ? x : f[x] = getf(f[x]);
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        f[i] = i;
        
    for (int i = 1; i <= m; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        if (getf(a) == getf(b))
            A.push_back(make_pair(make_pair(a, b), i));
        else
            f[getf(a)] = getf(b);
    }
    
    int ans = -1;
    for (int i = 1; i <= n; ++i) {
        if (getf(i) == i) {
            S.insert(i);
            ans += 1;
        }
    }
    
    printf("%d\n", ans);
    
    for (int i = 0, l = A.size(); i < l && ans > 0; ++i, --ans) {
        int x = A[i].first.first, y = A[i].first.second;
        int id = A[i].second;
        int fa = getf(x);
        S.erase(fa);
        int nt = *S.begin();
        printf("%d %d %d\n", id, y, nt);
        f[fa] = nt;
    }
    
    return 0;
}
 